package vh.sphynx.util;

import java.util.HashMap;

import vh.sphynx.runtime.ExecutionContext;
import vh.sphynx.runtime.NamedMemberProvider;

public class HashMapEx extends HashMap<Object, Object> implements
		NamedMemberProvider {

	private static final long serialVersionUID = 1L;
	private boolean extensible;
	private boolean readonly;
	private ExecutionContext context;
	
	
	public HashMapEx(boolean extensible, boolean readonly, ExecutionContext context) {
		this.extensible = extensible;
		this.context = context;
	}

	@Override
	public Object getMember(String name) {
		if (!extensible && !containsKey(name))
			throw new SphynxMemberNotFoundException(context, name);
		return get(name);
	}

	@Override
	public void setMember(String name, Object value) {
		if (!extensible && !containsKey(name))
			throw new SphynxMemberNotFoundException(context, name);
		put(name, value);
	}

	@Override
	public boolean isWritable() {
		return !readonly;
	}

	@Override
	public boolean isInitialized() {
		return true;
	}

	@Override
	public boolean hasMember(String name) {
		return containsKey(name);
	}

}
